package com.chouren.goandroid.ui.fragment.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chouren.goandroid.R;

public class RadioListAdapter extends BaseListAdapter<String> {
	private int selectedPosition;
	
	public RadioListAdapter(Context context, List<String> listData) {
		super(context, listData);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final Holder holder;
		
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.list_item_radio, parent, false);
			holder = new Holder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		
		final int pos = position;
		
		String inputName = listData.get(position);
		
		holder.mName.setText(inputName);
		if(getSelectedPosition() == pos) {
			holder.mThumb.setVisibility(View.VISIBLE);
		}else {
			holder.mThumb.setVisibility(View.INVISIBLE);
		}
		
		return convertView;
	}
	
	class Holder {
		ImageView mThumb;
		TextView mName;
		public Holder(View view) {
			mThumb = (ImageView) view.findViewById(R.id.radio_check);
			mName = (TextView) view.findViewById(R.id.radio_text);
		}
	}
	
	public void setSelectedPosition(int position) {
		this.selectedPosition = position;
	}
	
	public int getSelectedPosition() {
		return this.selectedPosition;
	}
	
}
